package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet("/demo2")
public class ServletDemo2 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //根据请求头名称获取一个值
        String connection = req.getHeader("connection");
        System.out.println(connection);

        System.out.println("-----------------------------");

        //根据请求头名称获取多个值  返回一个枚举
        Enumeration<String> values = req.getHeaders("accept-connection");
        //遍历
        while (values.hasMoreElements()){
            String value = values.nextElement();
            //打印获取到的值
            System.out.println(value);
        }


        System.out.println("-----------------------------");


        //获取所有的请求头名称
        Enumeration<String> names = req.getHeaderNames();
        while (names.hasMoreElements()){
            String name = names.nextElement();
            System.out.println(name);
        }

    }
}
